package com.haotian.http;

import java.util.Arrays;

public class _HttpResponse {

	private int code;

	private Object message;

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getStringMessage() throws Exception {

		if (message == null)
			return null;

		if (message instanceof String) {
			return String.valueOf(message);
		} else {
			throw new RuntimeException("Type is not an String");
		}

	}

	public byte[] getByteArrayMessage() throws Exception {

		if (message == null)
			return null;

		if (message.getClass().isArray()) {
			return (byte[]) message;
		} else {
			throw new RuntimeException("Type is not an array");
		}

	}

	public void setMessage(Object message) {
		this.message = message;
	}

	@Override
	public String toString() {
		return "_HttpResponse [code=" + code + ",message=" + (message==null?null:message instanceof String ? message.toString()
				: Arrays.toString(((byte[]) message))) + "]";
	}

}
